/*
 * @Author: szx
 * @Date: 2022-05-26 14:16:17
 * @LastEditTime: 2022-05-26 14:49:13
 * @Description:
 * @FilePath: \leetcode\面试题\10\11\11.js
 */
/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var wiggleSort = function (nums) {
    nums.sort((a, b) => b - a);
    let i = 0,
        j = nums.length - 1;
    const res = [];
    while (i < j) {
        res.push(nums[i++]).push(nums[j--]);
    }
    if (i == j) res.push(nums[i]);
    return res;
};
var wiggleSort = function (nums) {
    // 偶数是峰，奇数是谷
    for (let i = 1; i < numslength; i++) {
        if (i & 1) {
            if (nums[i] > nums[i - 1]) [nums[i], nums[i - 1]] = [nums[i - 1], nums[i]];
        } else {
            if (nums[i] < nums[i - 1]) [nums[i], nums[i - 1]] = [nums[i - 1], nums[i]];
        }
    }
};
